package com.example.dsplatform.Controller;

import cn.hutool.core.util.StrUtil;
import com.example.dsplatform.Dao.Mapper.OrderMapper;
import com.example.dsplatform.Service.OrderService;
import com.example.dsplatform.pojo.Entity.Order;
import com.example.dsplatform.pojo.Entity.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import static com.example.dsplatform.utls.timeStamp.time;
@RequestMapping("/Order")
public class OrderController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderService orderService;
    @PostMapping("/add")
    public ResponseResult addOrder(@RequestBody Order order){

        String orderNo = order.getOrderNo();
        String orderStatus = order.getStatus();
        if(StrUtil.isBlank(orderNo)||StrUtil.isBlank(orderStatus)){
            return new ResponseResult<>(205 ,"输入不合法，请重新输入");
        }
        order.setOrderStartTime(time());
        return orderService.addOrder(order);

    }
    @PostMapping("/delete")
    public ResponseResult deleteOrder(@RequestBody Order order){

        String orderNo = order.getOrderNo();
        String orderStartTime = order.getOrderStartTime();
        String orderStatus = order.getStatus();
        if(StrUtil.isBlank(orderNo)||StrUtil.isBlank(orderStartTime)||StrUtil.isBlank(orderStatus)){
            return new ResponseResult<>(205 ,"输入不合法，请重新输入");
        }

        return orderService.deleteOrders(order);

    }
    @PostMapping("/update")
    public ResponseResult updateOrder(@RequestBody Order order){

        String orderNo = order.getOrderNo();
        String orderStartTime = order.getOrderStartTime();
        String orderStatus = order.getStatus();
        if(StrUtil.isBlank(orderNo)||StrUtil.isBlank(orderStartTime)||StrUtil.isBlank(orderStatus)){
            return new ResponseResult<>(205 ,"输入不合法，请重新输入");
        }

        return orderService.updateOrders(order);

    }
    @PostMapping("/select")

    public ResponseResult seleteOrder(){


        return orderService.selectOrders();

    }

}
